package com.b511.swpu.cementbackend.controller;

import com.b511.swpu.cementbackend.dto.input.BoreholeConditionInputDto;
import com.b511.swpu.cementbackend.service.BurstPressureService;
import com.b511.swpu.cementbackend.service.MetaDictService;
import com.b511.swpu.cementbackend.dto.input.MetaDictInputDto;
import com.b511.swpu.cementbackend.entity.BurstPressure;
import com.b511.swpu.cementbackend.util.R;
import io.swagger.annotations.Api;
import org.springframework.data.domain.PageRequest;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(value = "地层破裂压力", tags = {"地层破裂压力"})
@RestController
@RequestMapping("/burst_pressure")
public class BurstPressureController {

    private final BurstPressureService burstPressureService;

    private final MetaDictService metaDictService;

    public BurstPressureController(BurstPressureService burstPressureService, MetaDictService metaDictService) {
        this.burstPressureService = burstPressureService;
        this.metaDictService = metaDictService;
    }

    @GetMapping("/{num}/{size}")
    public R getBurstPressure(@PathVariable int num, @PathVariable int size,  @ModelAttribute BoreholeConditionInputDto boreholeConditionInputDto) {
        return burstPressureService.getBurstPressureByCondition(boreholeConditionInputDto, PageRequest.of(num, size));
    }

    @PutMapping("/{id}")
    public R updateBorePressure(@PathVariable Long id, @RequestBody BurstPressure burstPressure) {
        return burstPressureService.updateBurstPressure(id, burstPressure);
    }

    @DeleteMapping("/{id}")
    public R deleteBurstPressure(@PathVariable Long id) {
        return burstPressureService.deleteBurstPressure(id);
    }

    @GetMapping("/dict/child")
    public R getDictByName(@ModelAttribute @Validated MetaDictInputDto metaDictInputDto) {
        return metaDictService.getDictByName(metaDictInputDto.getLabel());
    }
}
